<?php

namespace common\logics;

use Yii;
use common\models\dynamic\Dynamic;
use common\helpers\DateHelper;

/**
 * This is the model class for table "{{%topic}}".
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class TopicLogic extends \common\models\dynamic\Topic {

    public static function week() {
        $query = static::find()
        ->active(static::STATUS_ACTIVE)
        ->innerJoinWith('dynamic', false)
        ->limit(4);
        $weektime = DateHelper::timeInterval('week');
        if ($weektime !== false) {
            $query->andFilterWhere(['between', static::tableName() . '.created_at', $weektime['begintime'], $weektime['endtime']]);
        }
        return $query->all();
    }

    public function fields() {
        return [
            'id',
            'name',
            'comments',
            'dynamic',
        ];
    }

}
